<template>
  <div class="app-container">
    <el-card class="box-card">
      <div class="app-container-header">
        <el-form>
          <el-row :gutter="10">
            <el-col :span="3">
              <el-form-item>
                <el-input v-model="query.blurry" placeholder="请输入消息标题" />
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item>
                <el-select v-model="query.xxlx" clearable placeholder="请选择执消息类型" style="width: 100%">
                  <el-option
                    v-for="item in pt"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item>
                <el-form-item>
                  <el-select v-model="query.tslx" clearable placeholder="请选择推送方式" style="width: 100%">
                    <el-option
                      v-for="item in sentType"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-form-item></el-col>
            <el-col :span="6">
              <el-form-item>
                <el-date-picker
                  v-model="query.createTime"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd HH:mm:ss"
                />
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item>
                <el-button size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="app-container-table">
        <el-table
          ref="table"
          v-loading="loading"
          :data="dataList"
          highlight-current-row
          style="width: 100%;"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column :show-overflow-tooltip="true" prop="title" label="消息标题" />
          <el-table-column :show-overflow-tooltip="true" prop="updateTime" label="推送时间" />
          <el-table-column :show-overflow-tooltip="true" prop="xxlx" label="消息类型">
            <template slot-scope="scope">
              <span v-for="item in pt" :key="item.id">
                <span v-if="item.id === scope.row.xxlx">{{ item.name }}</span>
              </span>
            </template>
          </el-table-column>
          <el-table-column :show-overflow-tooltip="true" prop="tslx" label="推送方式">
            <template slot-scope="scope">
              <span v-for="item in sentType" :key="item.id">
                <span v-if="item.id === scope.row.tslx">{{ item.name }}</span>
              </span>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="query.page"
          :page-size="query.size"
          :total="pagerSize"
          style="margin-top: 8px;"
          layout="total, prev, pager, next, sizes"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </el-card>
  </div>
</template>
<script>
import { queryAllByPager } from '@/api/notice/notice/index';
import { queryAllTsfs, queryAllTspt } from '@/api/notice/constant/index';
export default {
  name: 'NoticeSendIndex',
  data() {
    return {
      pagerSize: 0,
      loading: false,
      dataList: [],
      sentType: [],
      pt: [],
      query: {
        blurry: '',
        type: '',
        xxlx: '',
        tslx: '',
        page: 1,
        size: 10,
        createTime: null
      }
    };
  },
  created() {
    this.initData();
    this.initTsfs();
    this.initTslx();
  },
  methods: {
    initTsfs() {
      queryAllTsfs().then(res => {
        const { data } = res;
        if (undefined !== data) {
          this.sentType = data.data;
        }
      });
    },
    initTslx() {
      queryAllTspt().then(res => {
        const { data } = res;
        if (undefined !== data) {
          this.pt = data.data;
        }
      });
    },
    initData() {
      this.loading = true;
      queryAllByPager(this.query).then(res => {
        const { data } = res;
        if (undefined !== data) {
          this.dataList = data.data;
          this.pagerSize = data.pagerSize;
        }
        this.loading = false;
      }).catch(() => {
        this.dataList = [];
        this.pagerSize = [];
        this.loading = false;
      });
    },
    toQuery() {
      this.query.page = 1;
      this.initData();
    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.initData();
    },
    handleSizeChange(val) {
      this.query.size = val;
      this.query.page = 1;
      this.initData();
    }
  }
};
</script>

<style scoped>

</style>
